import 'package:get/get.dart';
import 'package:xinxuan/http/http_util_service.dart';
import 'package:xinxuan/vo/common_vo/common_pagination_vo.dart';
import 'package:xinxuan/vo/gift_order_list_vo.dart';

class GiftOrderPageController extends GetxController {

  /// 赠品订单列表
  var giftOrderListVo = GiftOrderListVo(
    data: [],
    meta: GiftOrderMeta(
      pagination: CommonPagination(
        total: 0,
        currentPage: 1
      )
    )
  ).obs;
  
  @override
  void onReady() {
    getGitfOrderList();
    super.onReady();
  }

  /// 获取赠品订单列表
  getGitfOrderList() async {
    giftOrderListVo.value.meta!.pagination!.currentPage = 1;
    GiftOrderListVo tempVo = await HttpUtilService.getGitfOrderList(page: giftOrderListVo.value.meta!.pagination!.currentPage!);
    giftOrderListVo.value = tempVo;
    update();
  }

  /// 获取更多赠品订单列表
  onloadGitfOrderList() async {
    if (giftOrderListVo.value.meta!.pagination!.total! <= giftOrderListVo.value.data!.length) {
      return;
    }
    giftOrderListVo.value.meta!.pagination!.currentPage =  giftOrderListVo.value.meta!.pagination!.currentPage! + 1;
    GiftOrderListVo tempVo = await HttpUtilService.getGitfOrderList(page: giftOrderListVo.value.meta!.pagination!.currentPage!);
    giftOrderListVo.value.data!.addAll(tempVo.data!);
    update();
  }

}